//
//  RecordDetailViewController.m
//  AppleMarket
//
//  Created by yangy on 06/11/2018.
//  Copyright © 2018 szgsy. All rights reserved.
//

#import "RecordDetailViewController.h"
// model
#import "UserDeposit.h"

@interface RecordDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UILabel *moneyLabel;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSDictionary *itemsDictionary;
@property (nonatomic, strong) NSArray *labelsStrs;
@end

@implementation RecordDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = [NSString stringWithFormat:@"%@%@记录详情",self.deposit.CurrencyName,self.isDeposit? @"充值" : @"提现"];
    self.view.backgroundColor = [UIColor whiteColor];
    [self initUI];
    _labelsStrs = @[@"交易类型",@"资产类型",@"确认数",@"状态",@"时间",@"流水号"];
}

- (void) initUI
{
    [self.view addSubview:self.moneyLabel];
    [self.view addSubview:self.tableView];
    
    [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.mas_equalTo(self.view).offset(40);
    }];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.moneyLabel.mas_bottom).offset(49);
        make.left.right.mas_equalTo(self.view);
        make.bottom.mas_equalTo(self.view);
    }];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _labelsStrs.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
    if(cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
        cell.textLabel.font = kFont(14);
        cell.textLabel.textColor = kColorWithHex(0xB5C0CB);
        cell.textLabel.textAlignment = NSTextAlignmentLeft;
        cell.detailTextLabel.font = kFont(14);
        cell.detailTextLabel.textColor = kColorWithHex(0x0D2B47);
        cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    NSString *key = _labelsStrs[indexPath.row];
    cell.textLabel.text = key;
    cell.detailTextLabel.text = [self.itemsDictionary objectForKey:key];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 36;
}

- (UILabel *)moneyLabel
{
    if(!_moneyLabel){
        _moneyLabel = [UILabel cm_labelWithText:self.deposit.TradeAmount font:kFontBold(29) textColor:kColorWithHex(0x0E304C)];
    }
    return _moneyLabel;
}
- (UITableView *)tableView
{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        [_tableView setRowHeight:20];
        [_tableView setDelegate:self];
        [_tableView setDataSource:self];
        [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        [_tableView setScrollEnabled:NO];
    }
    return _tableView;
}

- (NSDictionary *)itemsDictionary
{
    if(!_itemsDictionary){
        _itemsDictionary = @{
                             @"交易类型" : @"充值",
                             @"资产类型" : self.deposit.CurrencyName,
                             @"确认数" : [NSString stringWithFormat:@"%ld",self.deposit.ConfirmCount],
                             @"状态" : self.deposit.ConfirmedStatusName,
                             @"时间" : self.deposit.CreateTime,
                             @"流水号" : self.deposit.SerialNumber
                             };
    }
    return _itemsDictionary;
}

@end
